package com.cj.service.impl;

import com.cj.dao.ClassDao;
import com.cj.po.DClass;
import com.cj.po.PageInfo;
import com.cj.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户Service接口实现类
 */
@Service("classService")
@Transactional
public class ClassServiceImpl implements ClassService {
    @Autowired
    private ClassDao classDao;
    @Override
    public PageInfo<DClass> findPageInfo(String c_classname,Integer c_classid,String c_counsellor, Integer pageIndex, Integer pageSize) {
//        return classDao.findPageInfo(s_name,s_classid,s_classid1,s_classname,pageIndex,pageSize);
        PageInfo<DClass> ci = new PageInfo<DClass>();
        ci.setPageIndex(pageIndex);
        ci.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = classDao.totalCount(c_classname,c_classid,c_counsellor);
        if (totalCount>0){
            ci.setTotalCount(totalCount);
            //每一页显示学生信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<DClass> classList =classDao.getClassList(c_classname,c_classid,c_counsellor, (ci.getPageIndex()-1)*ci.getPageSize(),ci.getPageSize());
            ci.setList(classList);
        }
        return ci;
    }

    @Override
    public List<DClass> getAll() {
        return  classDao.getAll();
    }

    @Override
    public int deleteClass(Integer c_id) {
        return classDao.deleteClass(c_id);
    }

    @Override
    public int addClass(DClass dClass) {
        return classDao.addClass(dClass);
    }

    @Override
    public int updateClass(DClass dClass) {
        return classDao.updateClass(dClass);
    }

    @Override
    public DClass findClassById(Integer c_id) {
        return classDao.findClassById(c_id);
    }


}
